import numpy as np
import sympy as sp

def mpower(base, exp, flag = True):
    if isinstance(exp, (float,int)):
        if flag:
            return sp.simplify(np.linalg.matrix_power(np.array(base), np.array(exp)))
        else :
            return np.linalg.matrix_power(np.array(base), np.array(exp))
    else:
        eigvals, eigvecs = np.linalg.eig(exp)
        D = np.diag(eigvals)
        D_power = np.diag([base**x for x in eigvals])
        result = eigvecs @ D_power @ np.linalg.inv(eigvecs)
        return sp.Matrix(result)

# Example usage
B = np.array([[1, 3], [4, 2]])
base = sp.pi
result = mpower(base, B)
print("The result of pi^B is:")
sp.pprint(result)
print(mpower(B, 2))